﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Catalog.CatalogItems;

namespace Catalog.CatalogTypes
{
    public class FilmCatalog : Catalog
    {
        static FilmCatalog()
        {
            AvailableFilms = new List<Film>();
        }

        private FilmCatalog()
        {
        }

        public static IList<Film> AvailableFilms { get; private set; }

        public static void AddNewItem(Film film)
        {
            AvailableFilms.Add(film);

            Catalog.AddNewItem(film);
        }

        public static void RemoveItem(Film film)
        {
            AvailableFilms.Remove(film);

            Catalog.RemoveItem(film);
        }

        public static string ShowAllFilms()
        {
            return FilmCatalog.ToString();
        }

        public static Film GetByName(string name)
        {
            foreach (var film in AvailableFilms)
            {
                if (film.Name == name)
                {
                    return film;
                }
            }

            throw new ArgumentException();
        }

        static new string ToString()
        {
            StringBuilder result = new StringBuilder();

            if (AvailableFilms.Count > 0)
            {
                result.AppendLine("All films: ");

                foreach (var item in AvailableFilms)
                {
                    result.AppendLine(string.Format("    {0}", item.ToString()));
                }
            }

            return result.ToString();
        }
    }
}